<template>
  <div>
    <el-table :data="tableData" border v-loading="loading" :header-cell-style="{'text-align':'center'}"
              :cell-style="{'text-align':'center'}">
      <el-table-column fixed prop="id" label="编号" width="85"></el-table-column>
      <el-table-column prop="code" label="代码" width="85"></el-table-column>
      <el-table-column prop="msg" label="状态" width="120"></el-table-column>
      <el-table-column prop="out_trade_no" label="订单号" width="130"></el-table-column>
      <el-table-column prop="send_pay_date" label="交易时间" width="135"></el-table-column>
      <el-table-column prop="total_amount" label="实付款" width="90"></el-table-column>
      <el-table-column prop="trade_no" label="交易号" width="260"></el-table-column>
      <el-table-column prop="trade_status" label="交易状态" width="220"></el-table-column>
      <el-table-column label="操作" width="130">
        <template slot-scope="scope">
          <el-popconfirm title="订单不可恢复，确定删除吗?" @confirm="delOrder(scope.row)">
            <el-button slot="reference" type="danger" icon="el-icon-delete">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="prev, pager, next"
                   :total="total" page-size="6" @current-change="page"
                   style="margin:20px;">
    </el-pagination>
  </div>
</template>

<script>
  export default {
    name: "Order",
    data() {
      return {
        pageSize: '1',
        total: null,
        tableData: null,
        loading: false
      }
    },
    methods: {
      page(currentPage) {
        const _this = this
        this.$axios.get('http://localhost:9000/trade/findPage/' + currentPage + '/6').then(function (resp) {
          _this.tableData = resp.data.content
          _this.pageSize = resp.data.size
          _this.total = resp.data.totalElements
        })
      },
      delOrder(row) {
        const _this = this
        this.$axios.delete('http://localhost:9000/trade/delById/' + row.id).then(function (resp) {
          _this.$alert('删除成功!', '消息', {
            confirmButtonText: '确定',
            callback: action => {
              window.location.reload()
            }
          });
        })
      }
    },
    created() {
      const _this = this
      this.$axios.get('http://localhost:9000/trade/findPage/1/6').then(function (resp) {
        _this.tableData = resp.data.content
        _this.pageSize = resp.data.size
        _this.total = resp.data.totalElements
      })
    }
  }
</script>

<style scoped>

</style>
